    //存放信息的变量
    var money;
    var objectArr;
    var thisNumer;
    var page = 1;
    var pagesize = 5;
    var totalpage;
    var searchArr = orderFormArr;
    var number; //存储新增页面订单金额的变量
    //给数组增添属性
    function addtype() {
        orderFormArr.map(function(item) {
            item.logisticsNumber = 1488333077758;
            item.returntype = '未发货,申请退货';
            return item;
        })
    }
    //渲染订单详情
    function orderrender() {
        objectArr = [];
        let buystorenumber = Math.floor(Math.random() * 4) + 1; //每个用户所买的商品数
        objectArr.push(buystorenumber);
        money = 0; //用户购买所用的钱
        $('.modtable').html(''); //每次渲染前情况tbody内容

        for (let j = 0; j < buystorenumber; j++) { //循环遍历购买商品的数量
            let storenumber = Math.floor(Math.random() * 9);
            objectArr.push(storenumber);
            money += parseFloat(storeguanli[storenumber].storepirce);
        }
        objectArr.push(money);
    }
    //渲染页面数据
    function orderpagedate(arr) {
        $('.pagetable').html(''); //每次渲染前清空tbody内容
        buystoreArr = []; //每次渲染前清空数组内容
        for (let i = 0; i < arr.length; i++) {
            orderrender();
            orderFormArr[i].orderMoney = money;
            orderFormArr[i].storepassege = objectArr;
        }
    }
    //渲染页面函数
    function orderRenderPage(arr) {
        $('.pagetable').html(''); //每次渲染前清空tbody内容
        for (let i = (page - 1) * pagesize; i < page * pagesize && i < arr.length; i++) {
            //给表格添加内容
            $('.pagetable').append(` <tr>
                    <td><input type="checkbox"  class='choose' date-Index = '${arr[i].id}'></td>
                    <td>${arr[i].id}</td>
                    <td>${arr[i].logisticsNumber}</td>
                    <td>${arr[i].orderNumber+parseInt(arr[i].id)-1}</td>
                    <td>${arr[i].buyerUserName}</td>
                    <td>${arr[i].returntype}</td>
                    <td>${arr[i].orderStatus}</td>
                    <td>
                        <button type="button"  date-orderIndex = '${i}' class="layui-btn layui-btn-sm ordermod"><i class="layui-icon "></i></button>
                        <button id="cc" type="button" date-orderIndex = '${arr[i].id}' class="layui-btn layui-btn-normal layui-btn-sm orderdel" style="background-color: red;"><i class="layui-icon"></i></button>
                    </td>
                </tr>`)
        }
    }
    //生成分页函数
    function orderpag(arr) {
        $('#test1').html('');
        totalpage = Math.ceil(arr.length / pagesize);
        if (page > totalpage) {
            page = totalpage;
        }
        if (totalpage == 0) {
            page = 1;
        }
        for (let i = 0; i < totalpage; i++) {
            $('#test1').append(`  <button class="currpage">${i+1}</button>`)
        }
        $('.currpage').eq(page - 1).addClass("cyan").siblings().removeClass("cyan");

    }
    //分页事件函数
    function pagevent(orderFormArr) {
        $('#test1').on('click', '.currpage', function() {
            page = $(this).text();
            orderRenderPage(orderFormArr);
        })
    }
    //事件委托函数
    function orderEvenEntrust() {
        $('.pagetable').on('click', '.orderdel', function() { //删除按钮操作
            let thisNumer = $(this).attr('date-orderIndex'); //获取删除按钮中的自定义属性找到数组中相对应的对象
            layer.confirm('确认删除？', {
                btn: ['确认', '取消'] //按钮
            }, function() {

                layer.msg('已删除', {
                    icon: 1,
                    time: 500

                });

                let delArr = orderFormArr.filter(function(item) { //点击确定删除按钮是过滤掉当前对象在数组中的值
                    return item.id != thisNumer;

                })
                orderFormArr = delArr;
                orderpag(orderFormArr);
                pagevent(orderFormArr);
                orderRenderPage(delArr); //重新渲染页面
            }, function() {
                layer.msg('已取消', {
                    icon: 2,
                    time: 500

                });
            });
        })

        $('.pagetable').on('click', '.choose', function() { //复选框按钮操作
            if ($('.choose:not(:checked)').length == 0) { //找到没有被选中的，如果leng==0；则全部被选中
                $(".cbxAll").prop("checked", true); //选中全选按钮
            } else {
                $(".cbxAll").prop("checked", false); //取消全选按钮
            }
        })

        $('.pagetable').on('click', '.ordermod', function() { //修改按钮操作
            thisNumer = parseInt($(this).attr('date-orderIndex')); //获取修改按钮中的自定义属性找到数组中相对应的对象
            $('#tanchukuang').show();
            //订单信息赋值
            $('#popup_box>div input').val('');
            $('.tbdashed>div>div>span').eq(1).html(parseInt(orderFormArr[thisNumer].orderNumber) + parseInt(orderFormArr[thisNumer].id - 1));
            $('.tbdashed>div>div>span').eq(3).html(orderFormArr[thisNumer].orderStatus);
            $('.tbdashed>div>div>span').eq(5).html(orderFormArr[thisNumer].shipmentStatus);
            $('.tbdashed>div>div>span').eq(7).html(orderFormArr[thisNumer].orderMoney);
            $('.tbdashed>div>div>span').eq(9).html(orderFormArr[thisNumer].buyerUserName);
            $('.tbdashed>div>div>span').eq(11).html(orderFormArr[thisNumer].paymentStatus);
            $('.tbdashed>div>div>span').eq(13).html(orderFormArr[thisNumer].orderMoney);
            $('.tbdashed>div>div>span').eq(15).html(orderFormArr[thisNumer].paymentMethod);
            $('.tbdashed>div>div>span').eq(17).html(orderFormArr[thisNumer].logisticsNumber);
            $('.tbdashed>div>div>span').eq(19).html(orderFormArr[thisNumer].returntype);
            $('.tbdashed>div>div>span').eq(21).html(orderFormArr[thisNumer].orderStatus);
            $('.tbdashed>div>div>span').eq(23).html(orderFormArr[thisNumer].orderMoney);

            $('#show').css('display', 'none');
            //渲染订单详情前清空信息
            $('.modtable').html('');
            for (let i = 0; i < orderFormArr[thisNumer].storepassege[0]; i++) {
                $('.modtable').append(`<tr>
                    <td>${storeguanli[orderFormArr[thisNumer].storepassege[i+1]].id}</td>
                    <td>${storeguanli[orderFormArr[thisNumer].storepassege[i+1]].storename}</td>
                    <td>${storeguanli[orderFormArr[thisNumer].storepassege[i+1]].storepirce}</td>
                    <td>0</td>
                    <td>1</td>
                    <td class= 'totalmoney'>${storeguanli[orderFormArr[thisNumer].storepassege[i+1]].storepirce}</td>
                </tr>`)
            }

        })
    }

    //搜索按钮函数
    function orderSearch() {
        $('.query').click(function() { //查询按钮
            searched('0', '010', 'returntype', '未发货,申请退货');
            searched('0', '021', 'returntype', '已审批');
            orderpag(searchArr);
            pagevent(searchArr);
            orderRenderPage(searchArr);
            searchArr = orderFormArr;
        })
        $('.reset').click(function() { //重置按钮操作

            orderpag(orderFormArr);

            page = 1;
            orderRenderPage(orderFormArr); //渲染原数组
        })
    }


    function searched(x, y, names, valued) {
        if ($('#show select').eq(x).val() == y) {

            searchArr = searchArr.filter(function(item) {

                return item[names] == valued;
            });

        }
    }
    //批量删除函数 
    function batchDel() {
        $('#DIB2').click(function() {
            if ($('.choose:checked').length > 0) {
                layer.confirm('确认全部删除？', {
                    btn: ['确认', '取消'] //按钮
                }, function() {
                    for (let j = 0; j < $('.choose:checked').length; j++) {
                        let thisIndex = $('.choose:checked').eq(j).attr('date-Index');
                        orderFormArr = orderFormArr.filter(function(item) {
                            return item.id != thisIndex;
                        })
                    }
                    orderpag(orderFormArr);
                    pagevent(orderFormArr);
                    orderRenderPage(orderFormArr); //重新渲染删除后的数组
                    layer.msg('已删除', {
                        icon: 1,
                        time: 500
                    });
                }, function() {
                    layer.msg('已取消', {
                        icon: 2,
                        time: 500
                    });
                });
            }
        })
    }
    //批量审批函数 
    function batchshenpi() {
        $('#DIB3').click(function() {
            if ($('.choose:checked').length > 0) {
                layer.confirm('确认全部审批？', {
                    btn: ['确认', '取消'] //按钮
                }, function() {
                    for (let j = 0; j < $('.choose:checked').length; j++) {
                        let thisIndex = parseInt($('.choose:checked').eq(j).attr('date-Index')) - 1;
                        orderFormArr[thisIndex].returntype = '已审批';
                    }
                    orderpag(orderFormArr);
                    orderRenderPage(orderFormArr);
                    layer.msg('审批成功', {
                        icon: 1,
                        time: 500
                    });
                });
            }
        })
    }

    //全选函数
    function allChoose() {

        $('.cbxAll').click(function() {
            let state = $('.cbxAll').prop('checked'); //获取全选按钮的checked状态
            $('.choose').prop('checked', state) //全选按钮的状态赋值给choose复选框
        })
    }

    //反选函数
    function pstChoose() {

        $('#delMuch').click(function() {
            for (let i = 0; i < $('.choose').length; i++) { //遍历choose复选框
                let state = !$('.choose').eq(i).prop('checked'); //获取choose每个复选框当前相反状态
                $('.choose').eq(i).prop('checked', state); //赋值给自己
            }
            if ($('.choose:not(:checked)').length == 0) {
                $(".cbxAll").prop("checked", true);
            } else {
                $(".cbxAll").prop("checked", false);
            }
        })

    }

    //返回列表函数
    function returnList() {
        $('.returnList').click(function() {
            $('#tanchukuang').hide();
            $('#addOrderpassege').hide();
            $('#show').show();
        })
    }

    //提交和重置按钮函数
    function modSubmit() {
        $('#tijiao').click(function() {
            layer.confirm('确认审批？', {
                btn: ['确认', '取消'] //按钮
            }, function() {
                orderFormArr[thisNumer].returntype = '已审批';
                orderpag(orderFormArr);
                orderRenderPage(orderFormArr)
                $('#tanchukuang').hide();
                $('#show').show();
                layer.msg('审批成功', {
                    icon: 1,
                    time: 500
                });
            });


        })
        $('#chongzhi').click(function() {
            $('#tanchukuang').hide();
            $('#addOrderpassege').hide();
            $('#show').show();
        })
        $('#addtijiao').click(function() {
            layer.confirm('是否确定新增？', {
                btn: ['确认', '取消'] //按钮
            }, function() {
                //获取退货订单中的值
                let select_no1 = $("#addOrderpassege select:eq(2)").find("option:selected").text();
                let select_no2 = $("#addOrderpassege select:eq(3)").find("option:selected").text();
                let select_no3 = $("#addOrderpassege select:eq(0)").find("option:selected").text();
                let select_no4 = $("#addOrderpassege select:eq(1)").find("option:selected").text();
                let inputname = $('#addOrderpassege input').eq(1).val();
                let inputmoney = $('#addOrderpassege input').eq(2).val();
                //赋值给数组
                if (select_no1 != '请选择' && select_no2 != '请选择' && select_no3 != '请选择' && select_no4 != '请选择' &&
                    inputmoney != '' && inputname != '') {
                    let addobject = {}; //存储新增退货订单的信息
                    addobject.returntype = select_no1;
                    addobject.orderStatus = select_no2;
                    addobject.orderMoney = inputmoney;
                    addobject.orderNumber = 1533019644791;
                    addobject.logisticsNumber = 1488333077758;
                    addobject.id = orderFormArr.length + 1;
                    addobject.buyerUserName = inputname;
                    addobject.storepassege = [1, number];
                    orderFormArr[orderFormArr.length] = addobject;
                    orderpag(orderFormArr);
                    orderRenderPage(orderFormArr);
                    $('#addOrderpassege').hide();
                    $('#show').show();
                    layer.msg('新增成功', {
                        icon: 1,
                        time: 500
                    });
                } else {
                    layer.msg('新增失败:请填写完整信息', {
                        icon: 2,
                        time: 800
                    });
                }

            });

        })
        $('#addchongzhi').click(function() {
            $('#tanchukuang').hide();
            $('#addOrderpassege').hide();
            $('#show').show();

        })
    }

    //添加订单函数
    function addorderlist() {
        $('#addbtn').click(function() {
            $('#addOrderpassege').show();
            $('#show').hide();
            let count1 = orderFormArr.length - 1;
            let count2 = orderFormArr[count1].orderNumber + count1 + 1;
            $('#addOrderpassege .firstinput').val(count2);
            $('#addOrderpassege .firstinput').attr('disabled', true);
        })
    }
    //新增订单select改变事件函数
    function selectchange() {
        $('#orderstoretype').change(function() {
            let orderstoretyp = $('#orderstoretype').val();
            if (orderstoretyp == 'sx') {
                $('#orderstorename').html(`<option value="iPhone6">Apple iPhone 6</option>
                   <option value="iPhone7">Apple iPhone 7</option>`)

            } else if (orderstoretyp == 'hw') {
                $('#orderstorename').html(`<option value="mate40">HUAWEI</option>`)


            } else if (orderstoretyp == 'vivo') {
                $('#orderstorename').html(`<option value="s7e">vivo s7e</option>
                   <option value="x23">vivo x23</option>`)

            } else if (orderstoretyp == 'bjb') {
                $('#orderstorename').html(`<option value="fxbl">飞行堡垒</option>`)

            } else if (orderstoretyp == 'iPad') {
                $('#orderstorename').html(`<option value="ipad">ThinkPad</option>`)

            } else if (orderstoretyp == 'fz') {
                $('#orderstorename').html(`<option value="vans">vans</option>
                   <option value="PUMA">PUMA</option>`)
            }
        })
    }
    //新增订单页面订单金额赋值函数
    function zhaoqian() {
        let select_no4 = $("#addOrderpassege select:eq(1)").find("option:selected").text();
        let number1;
        storeguanli.forEach(function(item, index) {
            if (item.storename == select_no4) {
                number1 = item.storepirce;
                number = index;
            }
        })
        $('#addOrderpassege input').eq(2).val(number1);

    }
    //上一页下一页点击事件函数
    function pagenumerevent(pagenuber) {
        $(pagenuber).click(function() {
            if (pagenuber == '#pagDow') {
                page--;
                for (let i = 0; i < $('.currpage').length; i++) {
                    let buttoncontent = parseInt($('.currpage').eq(i).text());
                    if (buttoncontent == page) {
                        $('.currpage').eq(i).addClass("cyan").siblings().removeClass("cyan");
                    }
                }
            } else if (pagenuber == '#pagUp') {
                page++;
                for (let i = 0; i < $('.currpage').length; i++) {
                    let buttoncontent = parseInt($('.currpage').eq(i).text());
                    if (buttoncontent == page) {
                        $('.currpage').eq(i).addClass("cyan").siblings().removeClass("cyan");
                    }
                }
            }
            if (page <= 0) {
                page = 1;
                $('.currpage').eq(0).addClass("cyan").siblings().removeClass("cyan");
            } else if (page >= totalpage) {
                page = totalpage;
            }
            orderRenderPage(orderFormArr);
        })
    }

    function callFunction() {
        orderpagedate(orderFormArr); //渲染页面数据函数;orderFormArr--初始数组
        addtype();
        orderRenderPage(orderFormArr); //渲染页面函数;

        orderEvenEntrust(); //事件委托函数
        orderSearch(); //搜索函数
        batchDel(); //批量删除函数
        batchshenpi(); //批量审批函数
        pstChoose(); //反选函数
        allChoose(); //全选函数
        returnList(); //返回列表函数
        modSubmit(); //修改页面按钮函数
        orderpag(orderFormArr); //生成分页函数
        pagevent(orderFormArr); //分页按钮点击事件（事件委托）
        addorderlist(); //添加订单函数
        selectchange(); //新增订单select改变事件函数
        setInterval(zhaoqian, 10); //新增订单页面订单金额赋值函数
        pagenumerevent('#pagDow')
        pagenumerevent('#pagUp')
    }
    callFunction();